/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Rada;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
/**
 *
 * @author Miguel
 */
public class RObject {
    public String html;
    public String style;
    public String nameclass, ID, name;
    public String width, height;
    public String background;
    public Map<String, String> events;
    public RObject(){
        events = new HashMap<String, String>();
        html="";
        background=null;
        nameclass=null;
    }
    public RObject(String id){
        events = new HashMap<String, String>();
        html="";
        background=null;
        nameclass=null;
        ID = id;
    }
    public String getProperties(){
        String pro="";
        if (ID!=null) pro+=" id='"+ID+"'";
        if (nameclass!=null) pro+=" class='"+nameclass+"'";
        if (name!=null) pro+=" name='"+name+"'";
        if (style!=null) pro+=" style='"+style+"'";
        if (width!=null) pro+=" width='"+width+"'";
        if (height!=null) pro+=" height='"+height+"'";
        return pro;
    }
    public void addEvent(String event, String function){
        if (events.containsKey(event))
            events.put(event, events.get(event)+";"+function);
        else
            events.put(event, function);
    }
    public String getEvents(){
        String eventos="";
        Set< String > keys = events.keySet(); // get keys
        TreeSet< String > sortedKeys = new TreeSet< String >( keys );
        for ( String key : sortedKeys ){
            eventos = key + " ='"+events.get( key )+";' ";
        }
            //System.out.printf( "%-10s%10s\n", key, events.get( key ) );
        return eventos;
    }
    public String show(){
        return html;
    }
}
